﻿// --------------------------------
// <copyright file="TableRowTest.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tronsoft.Actucal.Tables.Test
{
    
    
    /// <summary>
    ///This is a test class for TableRowTest and is intended
    ///to contain all TableRowTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TableRowTest
    {
        private const string TABLE_COLUMN_1 = "Col1";
        private const string TABLE_COLUMN_2 = "Col2";
        readonly DataTable dtTest = new DataTable();

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize()
        {
            // Define columns
            dtTest.Columns.Add(TABLE_COLUMN_1, typeof(int));
            dtTest.Columns.Add(TABLE_COLUMN_2, typeof(string));

            // Add new rows
            dtTest.Rows.Add(1, "Data1");
            dtTest.Rows.Add(2, "Data2");
        }
        
        //Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup()
        {
            dtTest.Columns.Clear();
            dtTest.Clear();
        }
        
        #endregion
        
        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void Should_Be_Able_To_Index_Row()
        {
            TableRow target = new TableRow(dtTest.Rows[1]);
            object actual = target[0];
            Assert.AreEqual(dtTest.Rows[1][0], actual);
        }

        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void Should_Be_Able_To_Index_On_ColumnName()
        {
            TableRow target = new TableRow(dtTest.Rows[0]); // TODO: Initialize to an appropriate value
            object actual = target[TABLE_COLUMN_2];

            Assert.AreEqual(dtTest.Rows[0][TABLE_COLUMN_2], actual);
        }

        /// <summary>
        ///A test for TableRow Constructor
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Should_NotFiniteNumberException_Accept_Null_Constructor()
        {
            TableRow target = new TableRow(null);
        }

        /// <summary>
        ///A test for RowData
        ///</summary>
        [TestMethod()]
        public void Should_Contain_The_DataRow_Data()
        {
            TableRow target = new TableRow(dtTest.Rows[0]); 
            object[] actual = target.RowData;

            Assert.AreEqual(dtTest.Rows[0].ItemArray.Length, actual.Length);

            for (int i = 0; i < dtTest.Rows[0].ItemArray.Length; i++ )
                Assert.AreEqual(dtTest.Rows[0].ItemArray[0], actual[0]);
        }
    }
}
